package com.zjinyin.forum.controller;

import com.zjinyin.forum.common.AppResult;
import com.zjinyin.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-08-08
 * Time: 17:14
 */

@RestController
@RequestMapping("/test")
@Api(tags = " 测试类相关接口 ")
public class TestController {

    @RequestMapping("/hello")
    public String fun () {
        return "hello Spring ";
    }

    @ApiOperation("保底策略异常测试接口")
    @RequestMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个 Exception 错误");
    }

    @ApiOperation("自定义异常测试接口")
    @RequestMapping("appException")
    public AppResult appException() {
        throw new ApplicationException("这是 appException");
    }

    @ApiOperation("测试用户名 API ")
    @RequestMapping("/name")
    public String getName(@ApiParam("用户名") @RequestParam("name") String name) {
        return "用户名 : " + name;
    }

}
